//
//  ZWProDetailHeadView.m
//  NewProject
//
//  Created by tongtong on 2018/5/18.
//  Copyright © 2018年 chenIos. All rights reserved.
//

#import "ZWProDetailHeadView.h"
@interface ZWProDetailHeadView()
@property (nonatomic,strong) UILabel *keyLabel;    //密钥
@property (nonatomic,strong) UILabel *moneyLabel;    //资金量
@property (nonatomic,strong) UILabel *switchLabel;    //资金换算
@end
@implementation ZWProDetailHeadView


#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubviews];
    }
    return self;
}

#pragma mark - add subviews
- (void)addSubviews {
    [self addSubview:self.keyLabel];
    [self addSubview:self.moneyLabel];
    [self addSubview:self.switchLabel];
    
    [self layoutSubviews];
}
#pragma mark - layout subviews
- (void)layoutSubviews {
    //  密钥
    ZWWeakSelf;
    [_keyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).offset(Scare_Width(40));
        make.left.equalTo(weakSelf.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_W, Scare_Width(25)));
    }];
   
    //  资金量
    __weak typeof(_keyLabel) weakKey = _keyLabel;
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakKey.mas_bottom).offset(Scare_Width(30));
        make.right.left.mas_equalTo(0);
        
//        make.size.mas_equalTo(CGSizeMake(SCREEN_W, Scare_Width(25)));
    }];
    //  资金换算
    __weak typeof(_moneyLabel) weakMoney = _moneyLabel;
    [_switchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakMoney.mas_bottom).offset(Scare_Width(12));
        make.left.equalTo(weakSelf.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_W, Scare_Width(20)));

    }];
   
    
}

- (void)configWithName:(NSString *)nameStr currencyUnit:(NSString *)currencyUnit money:(NSString *)money cny:(NSString *)cny{
    self.keyLabel.text = nameStr;
    double moneySign = money.doubleValue;
    self.moneyLabel.text = [NSString stringWithFormat:@"%.8lf",moneySign];
    if ([currencyUnit isEqualToString:@"CNY"]) {
        self.switchLabel.text = [NSString stringWithFormat:@"≈ ￥ %.2lf",cny.doubleValue];
      }else if([currencyUnit isEqualToString:@"USD"]){
        moneySign = cny.doubleValue/6.386;
        self.switchLabel.text = [NSString stringWithFormat:@"≈ $ %.2lf",moneySign];
    }
//    self.
  
}
#pragma mark - setter --
- (UILabel *)keyLabel {
    if (!_keyLabel) {
        _keyLabel = [[UILabel alloc] init];
        _keyLabel.textColor = COLOR_NAV_TITLE;
        _keyLabel.font = H2;
        _keyLabel.text= @"";
        _keyLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _keyLabel;
}
- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#5a697c"];
        _moneyLabel.text = @"0";
        _moneyLabel.font = H_Medium0;
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _moneyLabel;
}
- (UILabel *)switchLabel {
    if (!_switchLabel) {
        _switchLabel = [[UILabel alloc] init];
        _switchLabel.textColor = COLOR_MIDDLE_GRAY;
        _switchLabel.text = @"≈￥0";
        _switchLabel.font = H_Medium3;
        _switchLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _switchLabel;
}
@end
